package org.spiderflow.core.expression.parsing.ast.literal;

import org.spiderflow.core.expression.ExpressionTemplate;
import org.spiderflow.core.expression.ExpressionTemplateContext;
import org.spiderflow.core.expression.parsing.Span;
import org.spiderflow.core.expression.parsing.ast.Expression;

import java.io.IOException;

/**
 * A short literal. Must be marked with the <code>s</code> suffix, e.g. "123s".
 *
 * @author zsh
 */
public class ShortLiteral extends Expression {
    private final Short value;

    public ShortLiteral(Span literal) {
        super(literal);
        this.value = Short.parseShort(literal.getText().substring(0, literal.getText().length() - 1));
    }

    public Short getValue() {
        return value;
    }

    @Override
    public Object evaluate(ExpressionTemplate template, ExpressionTemplateContext context) throws IOException {
        return value;
    }
}